package com.lawliet.example.model;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.lawliet.example.config.LongToStringConvert;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

import static com.fasterxml.jackson.annotation.JsonProperty.Access.WRITE_ONLY;

@Data
@TableName("`sys_user`")
@Schema(title = "用户表")
//没有被ExcelProperty标记的字段导入导出时都会被忽略
@ExcelIgnoreUnannotated
public class User {

    @TableId(type = IdType.AUTO)
    @ExcelProperty(value = "主键",converter = LongToStringConvert.class)
    private Long id;

    @ExcelProperty("用户名")
    @Schema(title = "用户名")
    private String username;

    @JsonProperty(access = WRITE_ONLY)
    @Schema(title = "密码")
    private String password;

    @TableField(exist = false)
    @Schema(hidden = true)//swagger中忽略这个字段
    private String token;

    @ExcelProperty("角色")
    @Schema(title = "角色")
    @TableField(exist = false)
    private String role;

    @ExcelProperty("年龄")
    @Schema(title = "年龄")
    @TableField(exist = false)
    private Integer age;

    @ExcelProperty("电子邮箱")
    @Schema(title = "电子邮箱")
    private String email;

    /**
     * 创建人
     */
    @TableField(value = "create_by", fill = FieldFill.INSERT)
    private Long createBy;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Schema(title = "创建时间",description = "创建时自动添加",type = "String",format = "yyyy-MM-dd HH:mm:ss",example = "2025-02-28 12:24:00")
    private Date createTime;

    /**
     * 更新人
     */
    @TableField(value = "update_by", fill = FieldFill.UPDATE)
    private Long updateBy;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.UPDATE)
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Schema(title = "更新时间",description = "更新时自动添加",type = "String",format = "yyyy-MM-dd HH:mm:ss",example = "2025-02-28 12:24:00")
    private Date updateTime;
}